﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZF.BLL;

namespace ZF.WS.UserControls.House
{
    public partial class CZHouseType : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            using (var dc = SiteInfo.CreateDBDataContext())
            {
                Dictionary<object, List<object>> DicHoustType = new Dictionary<object, List<object>>();
                foreach (var ht in DictionaryConfig.HHouseType)
                {
                    var list = dc.H_House.Where(p => p.Status == 1 && p.IsVerify)
                        .Where(p => p.DealType == 1 || p.DealType == 2).Where(p => p.HouseType == ht.Key)
                        .OrderByDescending(p => p.HouseId).Take(20).ToList().Select(p =>
                         (object)new
                         {
                             Address = p.Address,
                             House = p,
                             City = SiteInfo.Instance.GetAreaOrDefault(p.AreaId1).Name,
                             Model = string.Format("{0}房{0}厅", p.HX_Fan, p.HX_Tin),
                             Price = p.Price,
                             AddTime = p.AddTime,
                             From = p.Form == 1 ? "个人" : "中介"
                         }).ToList();
                    DicHoustType[ht.Key] = list;
                }
                this.lvCZHouse.DataSource = DicHoustType;
                this.lvCZHouse.DataBind();



            }
            this.lvCZHouseType.DataSource = BLL.DictionaryConfig.HHouseType;
            this.lvCZHouseType.DataBind();
        }
    }
}